package com.young.shop.controller;

//import com.young.shop.pojo.entity.User;
//import com.young.shop.pojo.vo.BaseRespVO;
import com.young.shop.service.impl.OrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

//import javax.servlet.http.HttpServlet;
//import javax.servlet.http.HttpSession;

//用户点击我的订单
@WebServlet("/orders")
public class OrdersListController extends BaseController{

    OrderServiceImpl orderService = new OrderServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //解决跨域问题
        resp.setHeader("Access-Control-Allow-Origin","http://localhost:63342");
        //根据用户名查询用户的订单信息
//        HttpSession session = req.getSession();
//        String userName =(String) session.getAttribute("userName");

//        User user = jsonToObject(req, User.class);
//        String userId = user.getUserId();
        try {
            Long userId = 1L;
            List orderList = orderService.queryByUserId(userId);
//            System.out.println(orderList);
            writerSuccessResult(orderList,resp);
        }catch (Exception e){
            writerErrorResult(e.getMessage(),resp);
        }
    }
}
